import request from 'umi-request';

request.interceptors.request.use((url: any, options: any) => {
  //判断本地session是否有数据，如果有就得到token，并付给请求头
  if (localStorage.getItem('token') != null) {
    //获取到存在本地session里存的数据
    let c_token: any = localStorage.getItem('token');
    //转换获取到的数据格式，得到里面的token
    const headers = {
      Authorization: c_token,
    };
    return {
      url,
      options: { ...options, headers },
    };
  }
});